package com.boot.main.service.impl;

import com.boot.main.entity.ScomOrderProduct;
import com.boot.main.mapper.CcomUserMapper;
import com.boot.main.mapper.ScomOrderProductMapper;
import com.boot.main.response.ResponseData;
import com.boot.main.response.ResponseDataUtil;
import com.boot.main.service.IOrderProductService;
import com.boot.main.utils.IsNotEmptyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class OrderProductService implements IOrderProductService {
    @Resource
    private ScomOrderProductMapper orderProductMapper;

    @Resource
    private CcomUserMapper userMapper;

    @Override
    public ResponseData getOrderProducts(Integer page, Integer limit, String name){
        List<ScomOrderProduct> items = orderProductMapper.getOrderProducts((page-1)*limit, limit, name);
        Integer count = orderProductMapper.getTotalCount();
        Map map = new HashMap();
        map.put("datas",items);
        map.put("count", count);
        return ResponseDataUtil.success("获取订单产品成功", map);
    }

    @Override
    public ResponseData saveOrderProduct(ScomOrderProduct orderProduct){
        Integer num = orderProductMapper.saveOrderProduct(orderProduct);
        if(IsNotEmptyUtil.isEmpty(num)){
            return ResponseDataUtil.error("保存订单产品失败", null);
        }
        return ResponseDataUtil.success("保存订单产品成功", null);
    }

    @Override
    public ResponseData deleteOrderProduct(Long id){
        Integer num = orderProductMapper.deleteOrderProduct(id);
        return ResponseDataUtil.success("删除订单产品成功", null);
    }
}
